package com.aaa.controller.systemmanage;

import com.aaa.controller.BaseController;
import com.aaa.entity.MenuTree;
import com.aaa.entity.Result;
import com.aaa.entity.systemmanage.Menu;
import com.aaa.service.systemmanage.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单权限表(TblMenu)表控制层
 *
 * @author makejava
 * @since 2022-09-03 09:58:55
 */
@RestController
@RequestMapping("menu")
public class MenuController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private MenuService menuService;


    //普通查询给menu前端页面
    @RequestMapping(method = RequestMethod.GET, value = "/queryAllMenu.do")
    public Result queryAll() {
        List<Menu> menus = menuService.queryAll();
        return success(menus);
    }

    //给角色表的添加树型组件
    @RequestMapping(method = RequestMethod.POST, value = "/queryAllToSelect.do")
    public List<MenuTree> queryAllToSelect() {
        List<MenuTree> menus = menuService.queryAllToSelect();
        return menus;
    }

    //给角色表修改树型组件
    @RequestMapping(method = RequestMethod.POST, value = "/querySelect.do")
    public List<Integer> querySelect(int roleId) {
        return menuService.querySelect(roleId);
    }

    //修改菜单编号，名字，备注
    @RequestMapping(method = RequestMethod.POST, value = "/updateMenu.do")
    public Result update(Menu menu) {
        boolean update = menuService.update(menu);
        if (update) {
            return success("修改成功");
        } else {
            return fail("修改失败");
        }
    }


}

